<?
include("../lib/config.php");
include("../lib/var.php");
$nik 	= $HTTP_GET_VARS['nik'];
$op		= $HTTP_GET_VARS['op'];

if($op == "edit"){
	$Faction = "../lib/update.php";
	$Vbutton = "Update";
	$query	= mssql_query("SELECT *,convert(char(12), tgl_lahir, 103) tanggal FROM karyawan WHERE nik='$nik' ",$conn);
	$row	= mssql_fetch_array($query);
}
else{
	$Faction = "../lib/save.php";
	$Vbutton = "Simpan";
}

include("../header.php");
?>
<script type="text/javascript">
	function LoadFocus(){
		document.forms[0].elements[0].focus();
	}
	
	MaskInput = function(f, m){
	function mask(e){
		var patterns = {"1": /[A-Z]/i, "2": /[0-9]/, "4": /[\xC0-\xFF]/i, "8": /./ },
			rules = { "a": 3, "A": 7, "9": 2, "C":5, "c": 1, "*": 8};
		function accept(c, rule){
			for(var i = 1, r = rules[rule] || 0; i <= r; i<<=1)
				if(r & i && patterns[i].test(c))
					break;
				return i <= r || c == rule;
		}
		var k, mC, r, c = String.fromCharCode(k = e.key), l = f.value.length;
		(!k || k == 8 ? 1 : (r = /^(.)\^(.*)$/.exec(m)) && (r[0] = r[2].indexOf(c) + 1) + 1 ?
			r[1] == "O" ? r[0] : r[1] == "E" ? !r[0] : accept(c, r[1]) || r[0]
			: (l = (f.value += m.substr(l, (r = /[A|9|C|\*]/i.exec(m.substr(l))) ?
			r.index : l)).length) < m.length && accept(c, m.charAt(l))) || e.preventDefault();
	}
	for(var i in !/^(.)\^(.*)$/.test(m) && (f.maxLength = m.length), {keypress: 0, keyup: 1})
		addEvent(f, i, mask);
};

	function Validate(){
		if(document.FEmployee.nik.value == "")
		{
			alert("Field : NIK tidak boleh kosong ...");
			document.FEmployee.nik.focus();
			return false;
		}

		if(document.FEmployee.code_area.value == "")
		{
			alert("Field : Code Area tidak boleh kosong ...");
			document.FEmployee.code_area.focus();
			return false;
		}
		
		if(document.FEmployee.nama.value == "")
		{
			alert("Field : Nama Langkap tidak boleh kosong ...");
			document.FEmployee.nama.focus();
			return false;
		}

		if(document.FEmployee.tempat_lahir.value == "")
		{
			alert("Field : Tempat Lahir tidak boleh kosong ...");
			document.FEmployee.tempat_lahir.focus();
			return false;
		}

		if(document.FEmployee.tgl_lahir.value == "")
		{
			alert("Field : Tanggal Lahir tidak boleh kosong ...");
			document.FEmployee.tgl_lahir.focus();
			return false;
		}

		if(document.FEmployee.status.value == "")
		{
			alert("Field : Status tidak boleh kosong ...");
			document.FEmployee.status.focus();
			return false;
		}

		if(document.FEmployee.gender.value == "")
		{
			alert("Field : Gender tidak boleh kosong ...");
			document.FEmployee.gender.focus();
			return false;
		}

		if(document.FEmployee.agama.value == "")
		{
			alert("Field : Agama tidak boleh kosong ...");
			document.FEmployee.agama.focus();
			return false;
		}

		if(document.FEmployee.alamat.value == "")
		{
			alert("Field : Alamat tidak boleh kosong ...");
			document.FEmployee.alamat.focus();
			return false;
		}

		if(document.FEmployee.kota.value == "")
		{
			alert("Field : Kota tidak boleh kosong ...");
			document.FEmployee.kota.focus();
			return false;
		}

/*
		if(document.FEmployee.kode_pos.value == "")
		{
			alert("Field : Kode Pos tidak boleh kosong ...");
			document.FEmployee.kode_pos.focus();
			return false;
		}
*/
		if(document.FEmployee.propinsi.value == "")
		{
			alert("Field : Propinsi tidak boleh kosong ...");
			document.FEmployee.propinsi.focus();
			return false;
		}

		if(document.FEmployee.telepon.value == "")
		{
			alert("Field : Telepon tidak boleh kosong ...");
			document.FEmployee.telepon.focus();
			return false;
		}

<?
if($_GET['op'] == "edit"){

}
else{
?>
		if(document.FEmployee.jenjang.value == "")
		{
			alert("Field : Jenjang Pendidikan harus dipilih ...");
			document.FEmployee.jenjang.focus();
			return false;
		}
		
		if(document.FEmployee.fakultas.value == "")
		{
			alert("Field : Fakultas harus dipilih ...");
			document.FEmployee.fakultas.focus();
			return false;
		}
		
		if(document.FEmployee.jurusan.value == "")
		{
			alert("Field : Jurusan harus dipilih ...");
			document.FEmployee.jurusan.focus();
			return false;
		}

		if(document.FEmployee.nama_kampus.value == "")
		{
			alert("Field : Nama Kampus tidak boleh kosong ...");
			document.FEmployee.nama_kampus.focus();
			return false;
		}
		
		if(document.FEmployee.tempat.value == "")
		{
			alert("Field : Tempat tidak boleh kosong ...");
			document.FEmployee.tempat.focus();
			return false;
		}

<?
}
?>

		document.FEmployee.submit();
		
	}
	
	function show_popup(page)
	{
		child = open
		(
			page,
			"",
			"scrollbars,width=400,height=400,left=150,top=150"
		);
	}
</script>
</head>

<form name="FEmployee" method="post" enctype="multipart/form-data" action="<?=$Faction?>">
<table width="100%" class="border_line">
 <tr>
  <td colspan="2">
	<table width="100%" style="border:none;">
	<tr>
	 <td colspan="2" class="line_bottom">&nbsp;&nbsp;<b>Data Umum</b></td>
	</tr>
	<tr>
	 <tr>
	  <td>&nbsp;</td>
	 <td align="right">
	 <?
	 if($op == "edit"){
	 ?>
	 <a href="../lib/detailemp.php?show=pribadi&amp;nik=<?=$nik?>">Data Pribadi</a> &raquo; 
	 <a href="../lib/detailemp.php?show=data_umum&amp;nik=<?=$nik?>"><b>Data Umum</b></a> &raquo; 
	 <a href="../lib/detailemp.php?show=pendidikan&amp;nik=<?=$nik?>">Pendidikan</a> &raquo; 
	 <a href="../lib/detailemp.php?show=kecakapan&amp;nik=<?=$nik?>">Kecakapan</a> &raquo; 
	 <a href="../lib/detailemp.php?show=keluarga&amp;nik=<?=$nik?>">Keluarga</a> &raquo; 
	 <a href="../lib/detailemp.php?show=karir&amp;nik=<?=$nik?>">Pengalaman</a> &raquo; 
	 <a href="../lib/detailemp.php?show=organisasi&amp;nik=<?=$nik?>">Organisasi</a> 
	 <?
	 }
	 else{
	 
	 }
	 ?>
	 </td>
	 </tr>
	</table>
  </td>
 </tr>
 <tr>
 <td>
 <table>
 <tr>
  <td width="100"><b>NIK</b></td>
  <td>: <input type="text" maxlength="10" value="<?
  
  if(empty($row[NIK])){
	$nikgenerated = date("his");
	$nikrand = rand(0,9);
  	echo"$nikgenerated$nikrand";
  }
  else{
  	echo"$row[NIK]";
  }
  
  ?>" style="font-weight:bold;" class="text" name="nik" 
  <?
  	if($op == "edit"){
		echo"readonly='readonly'";
	}
	else{
	
	}
  ?>
   /> <span class="required">*</span></td>
 </tr>
 <tr>
  <td>Code Area</td>
  <td>:
   <select name="code_area">
		<?
			//$sCAa	= mssql_query("select AreaCode from MstSO Where AreaCode='$row[AreaCode]'",$conn);
			//while($rCAa = mssql_fetch_array($sCAa)){
				echo"<option value='$rCAa[AreaCode]'>$rCAa[AreaCode]</option>";
			//}
		?>
   <option value="">-Pilih-</option>
		<?
			$sCA	= mssql_query("select AreaCode from MstSO group by AreaCode",$conn);
			while($rCA = mssql_fetch_array($sCA)){
				echo"<option value='$rCA[AreaCode]'";
				if($row[AreaCode] == $rCA[AreaCode]){
					echo"selected";
				}else{
					if($rCA[AreaCode] == "SHO"){
						echo"selected";
					}
				}
				echo">$rCA[AreaCode]</option>";
			}
		?>
   </select> <span class="required">*</span>
   <input type="hidden" name="pelamar" value="0">
	</td>
 </tr>
 <tr>
  <td>Nama Lengkap</td>
  <td>: <input type="text" maxlength="50" value="<?=$row[Nama]?>" size="35" class="text" name="nama"/> <span class="required">*</span></td>
 </tr>
 <tr>
  <td>Tempat Lahir</td>
  <td>: <input type="text" maxlength="50" value="<?=$row[TempatLahir]?>" class="text" name="tempat_lahir"/> <span class="required">*</span></td>
 </tr>
 <tr>
  <td>Tanggal Lahir</td>
  <td>: <input type="text" maxlength="10" size="11" class="text" value="<?=$row[tanggal]?>" name="tgl_lahir"/> <span class="required">*</span> 
  <a href="javascript:cal.popup();"><img src="<?=$path?>/images/cal.gif" width="16" height="16" border="0" alt="Kalendar" title="Kalendar"></a> 
  <!--<span class="InfoForm">Format: dd/mm/yyyy</span>-->
  </td>
 </tr>
 <tr>
  <td>Status</td>
  <td>:
   <select name="status">
   <option value="">-Pilih-</option>
		<?
			$sSK	= mssql_query("select * from VStatusKawin",$conn);
			while($rSK = mssql_fetch_array($sSK)){
				echo"<option value='$rSK[kode]'";
				if($row[Status] == $rSK[kode]){
					echo" selected";
				}
				echo">";
				// cuma untuk bujangan
				if($rSK[nama] == "Bujangan"){
					echo"Single";
				}
				else{
					echo"$rSK[nama]";
				}
				echo"</option>";
			}
		?>
   </select> <span class="required">*</span>
  </td>
 </tr>
 <tr>
  <td>Gender</td>
  <td>: 
   <select name="gender">
    <option value="">-Pilih-</option>
	<option value="0" <? if($row[JKel] == 0) { echo"selected"; } ?>>Pria</option>
	<option value="1" <? if($row[JKel] == 1) { echo"selected"; } ?>>Wanita</option>
   </select> <span class="required">*</span>
  </td>
 </tr>
 <tr>
  <td>Agama</td>
  <td>: 
   <select name="agama">
   <option value="">-Pilih-</option>
		<?
			$sAG	= mssql_query("select * from VAgama",$conn);
			while($rAG = mssql_fetch_array($sAG)){
				echo"<option value='$rAG[kode]'";
				if($rAG[kode] == $row[Agama]){
					echo" selected";
				}
				echo">$rAG[nama]</option>";
			}
		?>
   </select> <span class="required">*</span>
  </td>
 </tr>
 <tr valign="top">
  <td valign="top">Alamat</td>
  <td valign="top">&nbsp; <textarea rows="4" cols="33" wrap="virtual" name="alamat"><?=$row[Alamat]?></textarea> <span class="required">*</span>
  </td>
 </tr>
 <tr>
  <td>Kelurahan</td>
  <td>: <input type="text" maxlength="20" name="kelurahan" value="<?=$row[Kelurahan]?>" /></td>
 </tr>
 <tr>
  <td>Kecamatan</td>
  <td>: <input type="text" maxlength="20" name="kecamatan" value="<?=$row[Kecamatan]?>" /></td>
 </tr>
 <tr>
  <td>Kota</td>
  <td>: <input type="text" maxlength="20" name="kota" value="<?=$row[Kota]?>" /> <span class="required">*</span></td>
 </tr>
 <tr>
  <td>Kode Pos</td>
  <td>: <input type="text" maxlength="5" size="5" name="kode_pos" value="<?=$row[KodePos]?>" /></td>
 </tr>
 <tr>
  <td>Propinsi</td>
  <td>: 
   <select name="propinsi">
   <?
   	echo'<option value="'.$row[Propinsi].'">'.$row[Propinsi].'</option>';
   ?>
   <option value="">-Pilih-</option>
		<?
			$sP	= mssql_query("select * from MstData where GroupCode='propinsi' order by Remarks asc",$conn);
			while($rP = mssql_fetch_array($sP)){
				echo"<option value='$rP[Remarks]'>$rP[Remarks]</option>";
			}
		?>
   </select> <span class="required">*</span>
  </td>
 </tr>
 <tr>
  <td>Negara</td>
  <td>: <input type="text" maxlength="50" name="negara" value="<?=$row[Negara]?>" /></td>
 </tr>
 <tr>
  <td>No. KTP</td>
  <td>: <input type="text" maxlength="25" size="25" name="no_ktp" value="<?=$row[NomorKTP]?>" /></td>
 </tr>
 <tr>
  <td>Telepon</td>
  <td>: <input type="text" maxlength="50" name="telepon" value="<?=$row[NoTelepon]?>" /> <span class="required">*</span></td>
 </tr>
 <tr>
  <td>Email</td>
  <td>: <input type="text" maxlength="50" size="35" name="email" value="<?=$row[Email]?>" /></td>
 </tr>
 <tr>
  <td>Upload Foto</td>
  <td>:
   <input type="file" name="file" />
  </td>
 </tr>
 <tr>
  <td colspan="2">&nbsp;</td>
 </tr>
<?
if($_GET['op'] == "edit"){

}
else{
?>
 <tr>
  <td colspan="2" bgcolor="#CFCFCF"><b>Pendidikan Terakhir</b></td>
 </tr>
 <tr>
	<td>Pendidikan</td>
	<td>
		  : <select name="jenjangold">
		  <option value="">-Select-</option>
		  <?
			$sP	= mssql_query("SELECT * FROM MstPendidikan ORDER BY keterangan",$conn);
			while($rP = mssql_fetch_array($sP)){
				echo"<option value='$rP[Pend_ID]'>$rP[keterangan] - $rP[jurusan]</option>";
			}
		  ?>
		  </select>
		  <span class="required">*</span></td>			
	</td>
 </tr>
 <tr>
  <td>Jenjang</td>
  <td>: 
  <select name="jenjang" id="JenjangPendidikan">
  <option value="">-Select-</option>
  <?
  	$sP	= mssql_query("SELECT * FROM Jenjang ORDER BY ordernum",$conn);
	while($rP = mssql_fetch_array($sP)){
		echo"<option value='$rP[id]'>$rP[nama]</option>";
	}
  ?>
  </select>
  <span class="required">*</span></td>
 </tr>
 <tr>
  <td>Fakultas</td>
  <td>: 
  <select name="fakultas" id="FakultasPendidikan">
  	<option value="">-Select-</option>
  </select>
  <span class="required">*</span></td>
 </tr>
 <tr>
  <td>Jurusan</td>
  <td>: 
  <select name="jurusan" id="JurusanPendidikan">
  <option value="">-Select-</option>
  </select>
  <span class="required">*</span></td>
 </tr>
 <tr>
  <td>Nama Kampus</td>
  <td>: <input type="text" maxlength="50" value="<?=$row[NamaKampus]?>"  class="text" size="50" name="nama_kampus"/> <span class="required">*</span></td>
 </tr>
 <tr>
  <td>Tempat</td>
  <td>: <input type="text" maxlength="50" value="<?=$row[Tempat]?>"  class="text" size="50" name="tempat"/> <span class="required">*</span></td>
 <tr>
  <td>Sampai Kelas/Semester</td>
  <td>: <input type="text" maxlength="10" value="<?=$row[SampaiKelas]?>" size="11"  class="text" name="sampai_kelas"/></td>
 <tr>
  <td>Dari</td>
  <td>: <input type="text" maxlength="10" value="<?=$row[tgl_dari]?>" size="11" class="text" name="dari"/><i> <a href="javascript:calB.popup();"><img src="../../images/cal.gif" width="16" height="16" border="0" alt="Kalendar" title="Kalendar"></i></td>
 </tr>
 <tr>
  <td>Sampai</td>
  <td>: <input type="text" maxlength="10" value="<?=$row[tgl_sampai]?>" size="11" class="text" name="sampai"/><i> <a href="javascript:calC.popup();"><img src="../../images/cal.gif" width="16" height="16" border="0" alt="Kalendar" title="Kalendar"></i></td>
 </tr>
  <td>No. Ijazah</td>
  <td>: <input type="text" maxlength="25" value="<?=$row[No_Ijasah]?>" class="text" name="no_ijazah"/></td>
 </tr>
 <tr>
  <td>Tanggal Ijazah</td>
  <td>: <input type="text" maxlength="10" value="<?=$row[tglijasah]?>" size="11"  class="text" name="tgl_ijazah"/> <a href="javascript:calA.popup();"><img src="../../images/cal.gif" width="16" height="16" border="0" alt="Kalendar" title="Kalendar"></a> 
  </td>
 </tr>
 <tr>
  <td>IPK</td>
  <td>: <input type="text" maxlength="4" value="<?=$row[IPK]?>"  size="6" class="text" name="ipk"/></td>
 </tr>
<? } ?> 
 <tr>
  <td>&nbsp;</td>
  <td align="left"><br /><br />
  <input type="hidden" name="foto" value="<?=$row[Foto]?>" />
  <input type="hidden" name="cat" value="employee" />
  <input type="reset" value="Batal" class="button" onclick="Javascript: history.back();" /><input type="button" value="<?=$Vbutton?>" class="button" onClick="Validate();" />
  <br /><br />
  </td>
 </tr>
</table>
</form>
</td>
</tr>
</table>
<script type="text/javascript">
//<![CDATA[

var f = document.forms[0];
/*MaskInput(f.elements[0], "(99)9999-9999");
MaskInput(f.elements[1], "99/99/9999");
MaskInput(f.elements[2], "Cc99-*C");
MaskInput(f.elements[3], "E^abc");
MaskInput(f.elements[4], "O^abc");
MaskInput(f.elements[5], "C^");
MaskInput(f.elements[6], "C^ ");
MaskInput(f.elements[7], "9^abc");
*/
MaskInput(f.tgl_lahir,"99/99/9999");
//MaskInput(f.telepon,"(99)9999-9999");
//]]>

// script untuk popup calendar
	var cal = new calendar1(document.forms['FEmployee'].elements['tgl_lahir']);
	cal.year_scroll = true;
	cal.time_comp = false;
	var calA = new calendar1(document.forms['FEmployee'].elements['tgl_ijazah']);
	calA.year_scroll = true;
	calA.time_comp = false;	
	var calB = new calendar1(document.forms['FEmployee'].elements['dari']);
	calB.year_scroll = true;
	calB.time_comp = false;	
	var calC = new calendar1(document.forms['FEmployee'].elements['sampai']);
	calC.year_scroll = true;
	calC.time_comp = false;	

</script>

<?
echo"</div>
	  </td>
	   </tr>
	    </table>
";
include("../menu.php");
?>